<?php
//角色

namespace app\admin\controller;


use app\admin\model\RoleReRoute;
use app\admin\model\RoleReUser;

class Role extends Base
{
    protected $middleware = ['app\admin\middleware\UpdateCacheAfter::class'];  //缓存控制器中间件

    public function filter(&$map, &$field)
    {

        $field = 'id,nickname,remark,create_time,status';
        $map = [['status', 'in', '1,2']];
    }


    public function beforeDetail(&$field)
    {
        $field = 'id,nickname,remark,status';
    }

    /**
     * Desc: 角色关联路由
     * User: 苏鹏
     * Date: 2023/9/21
     * Time: 10:54
     * @return void
     */
    public function roleReRoute()
    {
        $role_id = input('role_id', 0, 'intval');
        $roure_ids = input('route_ids', '');
        try{
            (new RoleReRoute())->setRoleReRoute($role_id, $roure_ids);
        }catch (\Exception $e){
            return re_error_json($e->getMessage());
        }
        return re_success_json();
    }

    /**
     * Desc: 角色关联用户
     * User: 苏鹏
     * Date: 2023/9/21
     * Time: 13:06
     * @return void
     */
    public function roleReUser()
    {
        $role_id = input('role_id', 0, 'intval');
        $user_ids = input('user_ids', '');
        try{
            (new RoleReUser())->setRoleReUser($role_id, $user_ids);
        }catch (\Exception $e){
            return re_error_json($e->getMessage());
        }
        return re_success_json();
    }
}